package com.lagou.rabbitmq.controller;

import com.lagou.rabbitmq.respository.PayRespository;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;


@Component
public class BizListener {
    @Autowired
    PayRespository payRespository;

    @RabbitListener(queues = "q.pay.dlx")
    public void getMyMessage(@Payload String bizId) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = simpleDateFormat.format(new Date());
        System.out.println("接受消息，time="+time+"，bizId="+bizId);
        if (!payRespository.exists(bizId)) {
            System.out.println("订单超时");
            // 说明订单超时，记录超时订单
            payRespository.setBizByTimeout(bizId);
            return;
        }
        System.out.println("订单已经支付");

    }


}
